package 集合.日常使用;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Description
 *
 * @Author: SunAo
 * @Date: 2022/4/26 19:48
 */
public class Collectors_flatMap方法 {

    @Data
    @AllArgsConstructor
    public static class Person{
        private List<String> sons;
    }

    @Test
    public void 元素为空时如何处理(){
        List<Person> eles = Arrays.asList(
                new Person(Arrays.asList("12", null, "3323")),
                new Person(Arrays.asList("122", null, null, "dadasf"))
        );

        List<String> sons = eles.stream()
                .flatMap(p -> p.getSons().stream())
                .collect(Collectors.toList());

        sons.stream().forEach(System.out::println);
    }

}
